<template>
  <div class="map-test-container">
    <div class="test-header">
      <h2>地图地址选择测试</h2>
      <button @click="showMapSelector" class="test-btn">打开地图选择器</button>
    </div>

    <div class="test-content">
      <div class="result-display">
        <h3>选择结果：</h3>
        <div class="result-item">
          <strong>地址：</strong>
          <span>{{ selectedAddress || '未选择' }}</span>
        </div>
        <div class="result-item">
          <strong>坐标：</strong>
          <span>{{ selectedLocation.lng ? `${selectedLocation.lng}, ${selectedLocation.lat}` : '未选择' }}</span>
        </div>
      </div>
    </div>

    <!-- 地图地址选择器 -->
    <MapAddressSelector
      v-model="selectedAddress"
      :show-modal="showMapModal"
      @update:show-modal="showMapModal = $event"
      @confirm="handleAddressConfirm"
    />
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import MapAddressSelector from '../components/MapAddressSelector.vue'

// 响应式数据
const showMapModal = ref(false)
const selectedAddress = ref('')
const selectedLocation = ref({ lng: 0, lat: 0 })

// 显示地图选择器
const showMapSelector = () => {
  showMapModal.value = true
}

// 处理地址确认
const handleAddressConfirm = (address: string, location: { lng: number, lat: number }) => {
  selectedAddress.value = address
  selectedLocation.value = location
  console.log('选择的地址:', address)
  console.log('坐标:', location)
}
</script>

<style scoped>
.map-test-container {
  padding: 20px;
  max-width: 800px;
  margin: 0 auto;
}

.test-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 30px;
}

.test-header h2 {
  margin: 0;
  color: #333;
}

.test-btn {
  background: #1890ff;
  color: white;
  border: none;
  padding: 12px 24px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
}

.test-btn:hover {
  background: #40a9ff;
}

.test-content {
  background: #f8f9fa;
  padding: 20px;
  border-radius: 8px;
}

.result-display h3 {
  margin: 0 0 15px 0;
  color: #333;
}

.result-item {
  margin-bottom: 10px;
  padding: 10px;
  background: white;
  border-radius: 4px;
  border: 1px solid #ddd;
}

.result-item strong {
  color: #333;
  margin-right: 10px;
}
</style>

